package com.css.fxfzypg.modules.baseData.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.baseData.repository.SlopeRepository;
import com.css.fxfzypg.modules.baseData.entity.Slope;
import com.css.fxfzypg.modules.baseData.service.SlopeService;
import com.css.fxfzypg.modules.baseData.queryParams.SlopeQueryParams;
import com.css.fxfzypg.modules.baseData.vo.SlopeVO;
import com.css.fxfzypg.util.FileUtil;
import com.css.fxfzypg.util.PlatformDateUtils;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.UUIDGenerator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;

@Service
public class SlopeServiceImpl implements SlopeService {
    @Resource
    SlopeRepository slopeRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public SlopeVO updateSlope(SlopeVO slopeVO) {

        SlopeVO slopeVO1 = slopeRepository.updateSlope(slopeVO);

        return slopeVO1;
    }

    @Override
    @Transactional
    public Slope saveSlope(Slope slope) {
        /*slope.setSlopeId(UUIDGenerator.getUUID());
        slope.setSlopeStatus(YNEnum.Y.toString());*/
        return slopeRepository.saveSlope(slope);
    }

    @Override
    public JSONObject getAllSlope(SlopeQueryParams queryParams) {
        return PlatformPageUtils.formatPageData(slopeRepository.getAllSlopeParams(queryParams));
    }

    @Override
    public Slope getSlopeById(String id) {
        Slope slope = slopeRepository.getSlopeById(id);
        return slope;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteSlopes(List<String> ids) {
        /*Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        slopeRepository.deleteSlopesById(ids,timestamp);*/
    }

    @Override
    public List<Slope> getAll() {

        return slopeRepository.getAll();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importExcel(MultipartFile file) throws IOException {
        /*List<Slope> slopes = FileUtil.importExcel(file, Slope.class);
        for(int i = 0 ; i<slopes.size();i++){
            slopes.get(i).setSlopeId(UUIDGenerator.getUUID());
            slopes.get(i).setSlopeStatus(YNEnum.Y.toString());

        }
        slopeRepository.importExcel(slopes);*/
    }
}
